package com.nerve.android.cloudoffice.app.worker;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @project: Cloudoffice_android
 * @file: LoadMessageManager.java
 * @package: com.nerve.android.cloudoffice.app.worker
 * @description:
 *	当加载最新消息线程工作完成后
 *	会通知到这个类，然后这个类会对 MessageLoadListener 进行广播
 * @author: 集成显卡	1053214511@qq.com
				IBM GDC, zengxm@cn.ibm.com
 * @date&time: Aug 22, 2013
 * @change log:
 */
public final class MessageLoadManager {
	
	private static Map<String, MessageLoadListener> listenerMap = new HashMap<String, MessageLoadListener>();
	
	/**
	 * @method name: addListener
	 * @description: 
	 * @return type: void
	 *
	 * @param listener
	 */
	public static void addListener(MessageLoadListener listener){
		synchronized (listenerMap) {
			listenerMap.put(listener.getLoaderName(), listener);
		}
	}
	
	/**
	 * @method name: messageLoadDone
	 * @description: 
	 * @return type: void
	 *
	 */
	public static void messageLoadDone(int size){
		Iterator<String> keys = listenerMap.keySet().iterator();
		
		while(keys.hasNext()){
			listenerMap.get(keys.next()).onMessageLoaded(size);
		}
	}
}